<template>
  <div>
    <!-- 年 -->
    <el-select v-model="currentYear" @change="dateChange">
      <el-option
        v-for="inde in yearList"
        :key="inde"
        :label="`${inde} 年`"
        :value="inde"
      />
    </el-select>
    <!-- 月 -->
    <el-select v-model="currentMonth" @change="dateChange">
      <el-option
        v-for="inde in 12"
        :key="inde"
        :label="`${inde}月`"
        :value="inde"
      />
    </el-select>
    <el-calendar v-model="currentDate">
      <!-- <template v-slot:dateCell="scope">{{ scope.data.type }}</template>
    </el-calendar> -->
      <template v-slot:dateCell="{ date, data }" class="content">
        <div class="date-content">
          <!-- 将当前日期号数显示出来 -->
          <span class="text"> {{ data.day | getDay }}</span>
          <!-- 每个周末才显示休息 -->
          <span v-if="isWeek(date)" class="rest">休</span>
        </div>
      </template>
    </el-calendar></div>
</template>

<script>
export default {
  filters: {
    getDay(vall) {
      return vall.split('-')[2]
    }
  },
  data() {
    // 创建日期对象
    const currentDate = new Date()
    // 日期对象获取月份
    const currentMonth = currentDate.getMonth() + 1
    // 获取api原生自带的日期年份
    const currentYear = currentDate.getFullYear()
    // 日期计算
    const yearList = []
    for (let i = 0; i < 10; i++) {
      yearList.push(currentYear - 3 + i)
    }
    return {
      currentDate,
      currentMonth,
      currentYear,
      yearList

    }
  },
  methods: {
    dateChange() {
      const str = this.currentYear + '/' + this.currentMonth
      this.currentDate = new Date(str)
    },
    isWeek(data) {
      // 判断休息日
    //   console.log(data)
      return data.getDay() === 6 || data.getDay() === 0
    }
  }

}
</script>

<style>
 ::v-deep .el-calendar-day {
  height:  auto;
 }
 ::v-deep .el-calendar-table__row td,::v-deep .el-calendar-table tr td:first-child,  ::v-deep .el-calendar-table__row td.prev{
  border:none;
 }
.date-content {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text{
  width: 20px;
  height: 20px;
  line-height: 20px;
 display: inline-block;

}
 ::v-deep .el-calendar-table td.is-selected .text{
   background: #409eff;
   color: #fff;
   border-radius: 50%;
 }
 ::v-deep .el-calendar__header {
   display: none
 }
</style>
